﻿using System;
using System.Collections.Generic;
using MSDNWebcast.Models;

namespace MSDNWebcast.ViewModels
{
    /// <summary>
    /// 课程视图
    /// </summary>
    public class CourseViewModel : ViewModelBase, ICleanUp
    {
        /// <summary>
        /// 课程
        /// </summary>
        private readonly Course m_Course;

        /// <summary>
        /// 课程课件
        /// </summary>
        private readonly List<CourseFileViewModel> m_CourseFiles;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="course"></param>
        public CourseViewModel(Course course)
        {
            m_Course = course;
            m_CourseFiles = new List<CourseFileViewModel>();
            foreach (FileType file in m_Course.Files)
                m_CourseFiles.Add(new CourseFileViewModel(file, course));
        }

        /// <summary>
        /// 课程ID
        /// </summary>
        public string EventID { get { return m_Course.EventID; } }

        /// <summary>
        /// 讲师
        /// </summary>
        public string Speaker
        {
            get { return m_Course.Speaker; }
        }

        /// <summary>
        /// 标题
        /// </summary>
        public string Headline
        {
            get { return m_Course.Headline; }
        }

        /// <summary>
        /// 描述
        /// </summary>
        public string Description
        {
            get { return "课程简介：" + m_Course.Description; }
        }

        /// <summary>
        /// 课程级别
        /// </summary>
        public int Level
        {
            get { return m_Course.Level; }
        }

        /// <summary>
        /// 课程系列
        /// </summary>
        public string Series
        {
            get { return m_Course.Series + ((m_Course.CourseIndex == 0) ? "" : String.Format("({0})", m_Course.CourseIndex)); }
        }

        /// <summary>
        /// 课程日期
        /// </summary>
        public String Date
        {
            get { return m_Course.Date.ToShortDateString(); }
        }

        /// <summary>
        /// 相关产品
        /// </summary>
        public string Products
        {
            get { return m_Course.Products; }
        }

        /// <summary>
        /// MSDN链接
        /// </summary>
        public string Url
        {
            get { return m_Course.Url; }
        }

        /// <summary>
        /// 视频路径
        /// </summary>
        public string VideoPath
        {
            get { return ""; }
        }

        /// <summary>
        /// 课程文件
        /// </summary>
        public List<CourseFileViewModel> CourseFiles
        {
            get { return m_CourseFiles; }
        }

        /// <summary>
        /// 有可供下载的课件
        /// </summary>
        public bool HasFiles
        {
            get { return m_CourseFiles != null && m_CourseFiles.Count > 0; }
        }

        /// <summary>
        /// 是否显示没有文件提示信息
        /// </summary>
        public bool ShowNoFilesInfo
        {
            get { return !HasFiles; }
        }

        public void CleanUp()
        {
            foreach (var courseFile in m_CourseFiles)
            {
                courseFile.CleanUp();
            }
        }
    }
}
